﻿/*
 * Copyright 2008 Pimm Hogeling, Karim Sempel and Demian Sempel
 * 
 * This file is part of 8bitplays.
 * 
 * 8bitplays is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 * 
 * 8bitplays is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with 8bitplays. If not, see <http://www.gnu.org/licenses/>.
 */
package nl.sandmen.team.main {
	import flash.events.EventDispatcher;
	import nl.sandmen.team.events.DiscographyLoaderEvent;
	import nl.sandmen.team.loaders.DiscographyLoader;
	/**
	 * @author Team Sandmen
	 */
	public class DataManager extends EventDispatcher {
		public var unusedAlbums:Array;
		private var discrographyLoader:DiscographyLoader;
		public function DataManager():void {
			unusedAlbums = new Array();
			discrographyLoader = new DiscographyLoader();
			discrographyLoader.addEventListener(DiscographyLoaderEvent.NEW_ALBUM, newAlbum);
			discrographyLoader.addEventListener(DiscographyLoaderEvent.END_OF_LIST, endOfList);
		}
		private function endOfList(e:DiscographyLoaderEvent):void {
			discrographyLoader.removeEventListener(DiscographyLoaderEvent.NEW_ALBUM, newAlbum);
			discrographyLoader.removeEventListener(DiscographyLoaderEvent.END_OF_LIST, endOfList);
			dispatchEvent(e);
			discrographyLoader = null;
		}
		public function load(albums:uint = 64, page:uint = 1, urlRequestHeaders:Array = null):void {
			discrographyLoader.loadDiscography(albums, page, urlRequestHeaders);
		}
		private function newAlbum(e:DiscographyLoaderEvent):void {
			unusedAlbums.push(e.album);
			TitleController.setTitle(unusedAlbums.length.toString(10) + " albums loaded");
		}
	}
}